package br.edu.ufcg.splab.util;

import static org.junit.Assert.assertTrue;

import java.io.FileNotFoundException;

import org.junit.Test;

import br.edu.ufcg.splab.core.InterfaceGenerate;
import br.edu.ufcg.splab.core.InterfaceGraph;
import br.edu.ufcg.splab.core.graph.Tree;
import br.edu.ufcg.splab.exceptions.LTSBTException;
import br.edu.ufcg.splab.generator.ConvertGraphToTree;
import br.edu.ufcg.splab.generator.TestCase;
import br.edu.ufcg.splab.generator.TestCaseGenerator;
import br.edu.ufcg.splab.generator.TestSuite;

public class MapTestSuiteTest {

	@Test
	public void testGetValueTestCase(){
		try{
			String transitionPairs = "./test-data/reduction/graph_test_reduction.tgf";
			
			ReadTGF parser = new ReadTGF();			
			InterfaceGraph graph = parser.getGraph(transitionPairs);
			
			InterfaceGenerate generator = new TestCaseGenerator();
			ConvertGraphToTree convertsGraphToTree = new ConvertGraphToTree();
			Tree tree = convertsGraphToTree.converterGraph(graph);
			tree.expand(1);
			TestSuite testSuite = generator.generate(tree);			
			
			MapTestSuite mapTS = new MapTestSuite(testSuite);
			
			assertTrue(1 == mapTS.getValueTestCase(testSuite.get(0)));
			assertTrue(2 == mapTS.getValueTestCase(testSuite.get(1)));
			assertTrue(3 == mapTS.getValueTestCase(testSuite.get(2)));
			assertTrue(4 == mapTS.getValueTestCase(testSuite.get(3)));
			assertTrue(5 == mapTS.getValueTestCase(testSuite.get(4)));
			assertTrue(6 == mapTS.getValueTestCase(testSuite.get(5)));
			assertTrue(7 == mapTS.getValueTestCase(testSuite.get(6)));
			assertTrue(8 == mapTS.getValueTestCase(testSuite.get(7)));
			assertTrue(9 == mapTS.getValueTestCase(testSuite.get(8)));
			assertTrue(10 == mapTS.getValueTestCase(testSuite.get(9)));
			assertTrue(11 == mapTS.getValueTestCase(testSuite.get(10)));
			assertTrue(12 == mapTS.getValueTestCase(testSuite.get(11)));
			assertTrue(13 == mapTS.getValueTestCase(testSuite.get(12)));
			
			assertTrue(15 != mapTS.getValueTestCase(testSuite.get(5)));
			
			TestCase tc = new TestCase();
			tc.addEdge(testSuite.get(0).get(0));
			tc.addEdge(testSuite.get(1).get(1));
			tc.addEdge(testSuite.get(2).get(2));
			tc.addEdge(testSuite.get(3).get(3));
			assertTrue(-1 == mapTS.getValueTestCase(tc));
			
		}catch (LTSBTException e){
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	@Test
	public void testGetTestCase(){
		try{
			String transitionPairs = "./test-data/reduction/graph_test_reduction.tgf";
			
			ReadTGF parser = new ReadTGF();			
			InterfaceGraph graph = parser.getGraph(transitionPairs);
			
			InterfaceGenerate generator = new TestCaseGenerator();
			ConvertGraphToTree convertsGraphToTree = new ConvertGraphToTree();
			Tree tree = convertsGraphToTree.converterGraph(graph);
			tree.expand(1);
			TestSuite testSuite = generator.generate(tree);			
			
			MapTestSuite mapTS = new MapTestSuite(testSuite);
			
			assertTrue(testSuite.get(0).equals(mapTS.getTestCase(1)));
			assertTrue(testSuite.get(1).equals(mapTS.getTestCase(2)));
			assertTrue(testSuite.get(2).equals(mapTS.getTestCase(3)));
			assertTrue(testSuite.get(3).equals(mapTS.getTestCase(4)));
			assertTrue(testSuite.get(4).equals(mapTS.getTestCase(5)));
			assertTrue(testSuite.get(5).equals(mapTS.getTestCase(6)));
			assertTrue(testSuite.get(6).equals(mapTS.getTestCase(7)));
			assertTrue(testSuite.get(7).equals(mapTS.getTestCase(8)));
			assertTrue(testSuite.get(8).equals(mapTS.getTestCase(9)));
			assertTrue(testSuite.get(9).equals(mapTS.getTestCase(10)));
			assertTrue(testSuite.get(10).equals(mapTS.getTestCase(11)));
			assertTrue(testSuite.get(11).equals(mapTS.getTestCase(12)));
			assertTrue(testSuite.get(12).equals(mapTS.getTestCase(13)));
			
			assertTrue(!testSuite.get(0).equals(mapTS.getTestCase(2)));
			assertTrue(!testSuite.get(5).equals(mapTS.getTestCase(1)));
			
			assertTrue(mapTS.getMapTestSuite().keySet().size() == testSuite.getTestSuite().size());
			
		}catch (LTSBTException e){
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}		
	}
}
